<?php
/*
	账户支付
	管理端支付接口
*/

defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'detail';
if($_RQ['op']=='detail'){
	$item=$this->plugin_setting('ks_setting');
	$canyu=pdo_get('jy_xiangqin_pingdatilog',array('issub'=>0,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'','id desc');
	$canyu['content']=json_decode($canyu['content'],true);
	if($canyu['id'] && count($canyu['content'])){
		$return['nowkey']=intval($canyu['nowkey']);
		$item['content']=$canyu['content'];
	}else{
		$tikus=$this->model('ping')->gettikus($item);
		$insert=array(
			'allscore'=>$item['allscore'],
			'content'=>$tikus,
		);
		$canyu['id']=$this->model('ping')->add_canyu($insert);
		$return['nowkey']=intval($_RQ['nowkey']);
		$item['content']=$tikus;
		$canyu['content']=$tikus;
	}
	$item['content']=array_values($item['content']);
	foreach($item['content'] as &$v){
		$v['typetitle']=$this->ti_types[$v['type']];
	}
	$return['nowitem']=$item['content'][$return['nowkey']];
	$return['allnum']=count($item['content']);
	$return['item']=$item;
	$return['banner']=json_decode($item['hdp'],true);
	$return['sharedata']=array(
		'title'=>$item['title'],
		'desc'=>$item['remark'],
		'link'=>custom_url('jy_xiangqin/ping.timu/',true),
		'imgUrl'=>ATTACHMENT_URL.$item['image'],
	);
	set_html('title',$item['title']);
	$return['post']=array('id'=>$canyu['id'],'nowkey'=>$return['nowkey'],'content'=>$item['content']);
	$return['danan_key']=$this->danan_key;
	exi($return);
}
if($_RQ['op']=='update'){
	$postdata=get_postdata();
	if($postdata){
		$this->model('model')->up_canyu($postdata);
	}
	exi('success');
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$getscore=$this->model('ping')->getscore($postdata['content']);
	pdo_update('jy_xiangqin_pingdatilog',array('issub'=>1,'allscore'=>$getscore['allscore'],'score'=>$getscore['score'],'content'=>ijson_encode($getscore['content'])),array('uniacid'=>$_SESSION['uniacid'],'id'=>$postdata['id']));
	exi('提交答卷成功','','jy_xiangqin/member.index/');
}